#未使用线程同步和互斥锁现象
from threading import Thread, Lock
from time import sleep


class Account:
    def __init__(self,money,name):
        self.money = money
        self .name =name

#模拟提款操作
class Drawing(Thread):
    def __init__(self,drawingNmu,account):
        Thread.__init__(self)
        self.account = account
        self .drawingNmu = drawingNmu
        self.expenseTotal = 0
    def run(self) :
        lock1.acquire()
        if self.account.money-self.drawingNmu<0:
            print("您的余额不足！")
            return
        sleep(1)#阻塞，导致两个线程都过，出现错误
        self.account.money-=self.drawingNmu
        self.expenseTotal+=self.drawingNmu
        lock1.release()
        print(f"账户:{self.account.name};余额是：{self.account.money}")
        print(f"账户:{self.account.name};总共取出：{self.expenseTotal}")

if __name__ == '__main__':
    a1 = Account(100,"duyongchuan")
    lock1 = Lock()
    draw1 = Drawing(80,a1)      #创建一个线程
    draw2 = Drawing(80,a1)  #创建另外一个线程
    draw1.start()   #你取钱
    draw2.start()   #你老婆取钱





